package cn.yunhe.action;

import cn.yunhe.service.NewsService;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

@Controller
@Scope("prototype")
@ParentPackage("json-default")
public class NewsManagerAction extends ActionUtil {

    private Map<String,Object> newsMap = new HashMap<String, Object>();

    @Autowired
    @Qualifier("newsService")
    private NewsService newsService;

    @Action(value = "news_getAllNews",results = {
            @Result(type = "json",params = {"root","newsMap"})
    })
    public String getAllNews(){
        newsMap = newsService.getAllNews(1);
        return SUCCESS;
    }

    public Map<String, Object> getNewsMap() {
        return newsMap;
    }

    public void setNewsMap(Map<String, Object> newsMap) {
        this.newsMap = newsMap;
    }

    public NewsService getNewsService() {
        return newsService;
    }

    public void setNewsService(NewsService newsService) {
        this.newsService = newsService;
    }
}
